Skip to content

Add to PATH if we don't need to install#93

Open
TylerLeonhardt wants to merge 2 commits into
PowerShellOrg:masterfrom
TylerLeonhardt:fix-add-to-path
Open

Add to PATH if we don't need to install#93
TylerLeonhardt wants to merge 2 commits into
PowerShellOrg:masterfrom
TylerLeonhardt:fix-add-to-path

Conversation

@TylerLeonhardt
Copy link
Copy Markdown
Contributor

@TylerLeonhardt TylerLeonhardt commented Oct 26, 2018

Previous logic wouldn't add 'dotnet' to the PATH if it didn't need to be installed (because it was already present).

This will ensure that the .NET SDK is added to the PATH every time you do: Invoke-PSDepend

PATH logic is fun...

cc @SeeminglyScience

@TylerLeonhardt
Copy link
Copy Markdown
Contributor Author

TylerLeonhardt commented Oct 26, 2018

rip - works outside of the tests 🙃 probably some magic path stuff. Digging...

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the DotnetSdk dependency type to ensure the .NET SDK is added to the current session PATH even when installation is skipped because a suitable SDK is already present, and adds/updates tests + error messages to reflect the new behavior.

Changes:

  • Always run .NET SDK -> PATH logic during Install by calling a new Import-Dotnet helper.
  • Introduce Import-Dotnet (Private) to centralize PATH/SDK discovery and version validation.
  • Extend DotnetSdk Pester tests with Get-Command dotnet assertions and update the expected error message.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
Tests/PSModuleGallery.Type.Tests.ps1 Adds assertions that dotnet is discoverable after Invoke-PSDepend and updates an expected error message.
PSDepend/PSDependScripts/DotnetSdk.ps1 Calls Import-Dotnet during Install and delegates Import behavior to the helper.
PSDepend/Private/Import-Dotnet.ps1 New helper that attempts to ensure a sufficiently new .NET SDK is discoverable via PATH.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$globalDotnetSdkLocation = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }

$dotnetInPath = Get-Command 'dotnet' -ErrorAction SilentlyContinue
$dotnetInPathIsGood = $dotnetInPath -and (Test-Dotnet -Version $Version -InstallDir $dotnetInPath.Source)
Comment on lines +89 to 94

Import-Dotnet -Version $Version -InstallDir $InstallDir
}

# Handle 'Import'
if ($PSDependAction -contains 'Import') {
Comment on lines 909 to +911
Invoke-PSDepend @Verbose -Path "$TestDepends\dotnetsdk.complex.depend.psd1" -Force
Test-Path $SavePath | Should -BeTrue
{ Get-Command 'dotnet' } | Should -Not -Throw
Comment on lines 918 to +920
Invoke-PSDepend @Verbose -Path "$TestDepends\dotnetsdk.complex.depend.psd1" -Force
Assert-MockCalled -CommandName Install-Dotnet -Times 0 -Exactly
{ Get-Command 'dotnet' } | Should -Not -Throw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants